
#include "NewRSAKeyPair.h"

int NewRSAKeyPair::GenerateKeyPair(int nbits, const char *name)
{
   RSA *rkey = RSA_generate_key(nbits, 0x10001, NULL, NULL);
   if (!rkey) { fSSLCheckError(); return -1; }
   pub = new RSAPublicKey(rkey, name);
   prv = new RSAPrivateKey(rkey, name);
   return (CheckAreKeyPair()) ? 0 : 1;
}

NewRSAKeyPair::NewRSAKeyPair(int nbits, const char *name)
{
   GenerateKeyPair(nbits, name);
}

int NewRSAKeyPair::CheckAreKeyPair()
{
   return CheckAreKeyPair(pub, prv);
}

int NewRSAKeyPair::CheckAreKeyPair(RSAPublicKey *ipub, RSAPrivateKey *iprv)
{
   return iprv->CompareKeyBelongs(ipub);
}
